<template>
	<view class="container">
		<scroll-view scroll-y="true" class="scrollContainer">
			<view class="searchAndBannerContainer">
				<view class="searchContainer">
					<text style="font-size: 40rpx;color: #FFFFFF;margin-right: 10rpx;">艾兴合</text>
					<input class="uni-input searchInput" focus placeholder="搜索商品" />
					<view class="scanContainer" @click="scanQRCode">
						<image style="width: 40rpx; height: 40rpx;" src="@/static/scan.png"></image>
						<text style="color: white;font-size: 30rpx;margin-top: 5rpx;">扫一扫</text>
					</view>
				</view>
			</view>
			<view class="bannerContainer">
				<swiper class="swiper" circular :indicator-dots="true" :autoplay="true" :interval="2000"
					:duration="500">
					<swiper-item>
						<view class="swiper-item">
							<image class="swiper-item-image"
								src="https://p9.itc.cn/q_70/images03/20220218/4d81e94e5c6d444c8885f96921405497.jpeg">
							</image>
						</view>
					</swiper-item>
					<swiper-item>
						<view class="swiper-item">
							<image class="swiper-item-image"
								src="https://p0.itc.cn/q_70/images03/20220218/995c8361ee674211aeeb37cbc6de2e9e.jpeg">
							</image>
						</view>
					</swiper-item>
					<swiper-item>
						<view class="swiper-item">
							<image class="swiper-item-image"
								src="https://p7.itc.cn/q_70/images03/20220218/82be34ec854b44c2b8e892de0be5e7ad.jpeg">
							</image>
						</view>
					</swiper-item>
				</swiper>
			</view>

			<view class="IndustryEntry">
				<uni-grid :column="5" :highlight="true" @change="change">
					<uni-grid-item v-for="(item, index) in 10" :index="index" :key="index">
						<view class="grid-item-box" style="background-color: #fff;">
							<uni-icons type="image" :size="20" color="#777" />
							<text style="font-size: 20rpx;">文本信息</text>
						</view>
					</uni-grid-item>
				</uni-grid>
			</view>

			<view class="preferred-commodity">
				<uni-grid :column="2" :highlight="true" @change="change">
					<uni-grid-item v-for="(item, index) in 4" :index="index" :key="index">
						<view class="grid-item-box" style="background-color: #fff;">
							<uni-icons type="image" :size="30" color="#777" />
							<text class="text">文本信息</text>
						</view>
					</uni-grid-item>
				</uni-grid>
			</view>


			<view>
				<zero-waterfall :list="dataList">
					<!--  #ifdef  MP-WEIXIN -->
					<view v-for="(item, index) of dataList" :key="index" slot="slot{{item.id}}">
						<view class="cnt">
							<view class="text">{{ item.extra }}</view>
						</view>
					</view>
					<!--  #endif -->

					<!-- #ifndef  MP-WEIXIN -->
					<template v-slot:default="item">
						<view class="cnt">
							<view class="text">{{ item.extra }}</view>
						</view>
					</template>
					<!-- #endif -->
				</zero-waterfall>
				<uni-load-more bg-color="rgb(240, 240, 240)" :status="loadStatus"
					@clickLoadMore='loadMore'></uni-load-more>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				arr: [{
						id: 1,
						url: "https://gimg2.baidu.com/imag_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp09%2F21052112102250D-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643473244&t=b5e08380ae592167bc023b5809a46d1e",
						title: "网络图片1(错误的图片地址)",
						note: "网络图片1,已经失效的图片",
						extra: '自定义slot信息',

					},
					{
						id: 2,
						url: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp09%2F21052112102250D-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643473244&t=b5e08380ae592167bc023b5809a46d1e",
						title: "网络图片2",
						note: "网络图片2,可能会失效!网络图片,可能会失效!网络图片,可能会失效!",
						extra: '自定义slot信息',
					},
					{
						id: 3,
						url: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp09%2F210611094Q512b-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643473244&t=72c2f08503aeba6b3988f2d96f83775e",
						title: "网络图片3",
						note: "网络图片3,可能会失效!",
						extra: '自定义slot信息',
					},
					{
						id: 4,
						url: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fnimg.ws.126.net%2F%3Furl%3Dhttp%3A%2F%2Fdingyue.ws.126.net%2F2021%2F0628%2F29618e08j00qverj7001ec000ci00loc.jpg%26thumbnail%3D650x2147483647%26quality%3D80%26type%3Djpg&refer=http%3A%2F%2Fnimg.ws.126.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643473244&t=f1af25d8ea22fda465b7f3e37d9c9fa7",
						title: "网络图片4",
						note: "网络图片4,可能会失效!网络图片,可能会失效!",
						extra: '自定义slot信息',
					},
					{
						id: 5,
						url: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.jj20.com%2Fup%2Fallimg%2F1114%2F0G320103935%2F200G3103935-1-1200.jpg&refer=http%3A%2F%2Fpic.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643473244&t=f65fa05e38a04d9544a46af86f94b7e8",
						title: "网络图片5",
						note: "网络图片5,可能会失效!",
						extra: '自定义slot信息',
					},
					{
						id: 6,
						url: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp01%2F1ZZQ20QJS6-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643473244&t=85113db32df432853292930e541c1af5",
						title: "网络图片6",
						note: "网络图片6,可能会失效!网络图片,可能会失效!",
						extra: '自定义slot信息',
					},
					{
						id: 7,
						url: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fnimg.ws.126.net%2F%3Furl%3Dhttp%253A%252F%252Fdingyue.ws.126.net%252F2021%252F0531%252F0a85fb25j00qtxwjo000ic000hs00hsc.jpg%26thumbnail%3D650x2147483647%26quality%3D80%26type%3Djpg&refer=http%3A%2F%2Fnimg.ws.126.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643473244&t=4d51c25fa34adee1c02af11d65e910ac",
						title: "网络图片7",
						note: "网络图片7,可能会失效!网络图片,可能会失效!网络图片,可能会失效!",
						extra: '自定义slot信息',
					},
				],
				loading: false,
				dataList: [],
				loadStatus: 'more',
				page: 1,
				pageSize: 5,
			}
		},
		onLoad() {

		},
		created() {
			this.dataList = this.arr.slice(0, 5)
		},
		onReachBottom() {
			if (this.dataList.length >= this.arr.length) {
				this.loadingStatus = 'noMore'
			} else {
				this.loadStatus = 'more';
				setTimeout(() => {
					this.loadMore();
					this.loadStatus = 'loadmore';
				}, 1000)
			}

		},
		methods: {
			scanQRCode() {
				// 允许从相机和相册扫码
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
					}
				});
			},
			change(e) {
				uni.showToast({
					title: `点击第${index+1}个宫格`,
					icon: 'none'
				})
			},
			// 模拟数据加载
			loadMore() {
				this.loadStatus = 'loading';
				this.page++
				this.dataList = this.dataList.concat(this.arr.slice(this.dataList.length, this.page * this.pageSize))
			},
		}
	}
</script>

<style scoped>
	.container {
		width: 100vw;
		height: 100%;
		background-color: crimson;
	}

	.scrollContainer {
		width: 100vw;
		height: 100%;
	}

	.searchAndBannerContainer {
		display: flex;
		flex-direction: column;
	}

	.searchContainer {
		flex-direction: row;
		display: flex;
		align-items: center;
		padding: 20rpx;
	}

	.scanContainer {
		display: flex;
		margin-left: 10rpx;
		flex-direction: column;
		align-items: center;
	}

	.searchInput {
		border-radius: 50rpx;
		height: 60rpx;
		flex-grow: 1;
		background-color: #FFFFFF;
		padding-left: 15rpx;
		padding-right: 15rpx;
	}

	.swiper {
		height: 300rpx;
	}

	.swiper-item {
		display: block;
		height: 300rpx;
		line-height: 300rpx;
		text-align: center;
	}

	.swiper-item-image {
		width: 100%;
		height: 300rpx;
		border-radius: 15rpx;
	}

	.bannerContainer {
		padding-left: 15rpx;
		padding-right: 15rpx;
	}

	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	.IndustryEntry {
		margin-top: 20rpx;
		margin-left: 20rpx;
		margin-right: 20rpx;
		display: flex;
		flex-direction: column;
	}

	.preferred-commodity {
		border-radius: 20rpx;
		margin-top: 20rpx;
		margin-left: 20rpx;
		margin-right: 20rpx;
		background-color: #FFFFFF;
		padding: 20rpx;
	}
</style>